package com.harmontronics.hanma.paas.paas.config;

import com.harmontronics.hanma.paas.paas.config.xss.XssHttpServletRequestWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.ObjectUtils;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * 防止XSS攻击的过滤器
 *
 * @author ruoyi
 */
public class AppUniqueFilter implements Filter {
    public static final String APP_UNIQUE="App-Unique";


    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {

        AppUniqueHttpServletRequest uniqueHttpServletRequest = new AppUniqueHttpServletRequest((HttpServletRequest) request);
        if (ObjectUtils.isEmpty(uniqueHttpServletRequest.getHeader(APP_UNIQUE))) {
            uniqueHttpServletRequest.addHeader(APP_UNIQUE, "master");
        }
        chain.doFilter(uniqueHttpServletRequest, response);
    }


    @Override
    public void destroy() {

    }
}
